package interfaces

import (
	"gitee.com/captials-team/ubdframe/src/domain/dto"
	"gitee.com/captials-team/ubdframe/src/domain/dto/paginate"
	"gitee.com/captials-team/ubdframe/src/domain/dto/respdata"
	"gitee.com/captials-team/ubdframe/src/domain/models"
)

type ItfAuthService interface {
	DoAuth(*dto.AccountLoginParams) (*dto.AuthInfo, error)
}

type ItfUserService interface {
	SignUp(*dto.UserRegisterParams) (int64, error)
	SaveUser(id int64, up *models.User) (int64, error)
	AutoCreateUser(nickname string, account string, password string) error

	ItfAuthService
}

type ItfAdminService interface {
	ValidatePassword(adminId int64, password string) (bool, error)          //验证密码是否正确
	AutoCreateAdmin(nickname string, account string, password string) error //自动创建超级管理员

	Search(search *dto.SearchAdminParams, pa *paginate.Pager) ([]*models.Admin, *paginate.Pager, error)

	ResetStatus(id int64, status int) (int64, error)
	ResetPassword(id int64, password string) (int64, error)
	ResetRootPassword(id int64, password string) (int64, error)
	UpdateProInfo(id int64, profile *dto.UpdateProfileParams) (int64, error)
}

type ItfSettingService interface {
	Set(key, value string) error
	Get(key string) (string, error)

	SetMulti(data map[string]string) error
	GetMulti(keys ...string) (map[string]string, error)

	GetFromCache(key string) (string, error)
	GetMultiFromCache(keys ...string) (map[string]string, error)
}

// ItfBlockContentService 块内容service
type ItfBlockContentService interface {
	Search(search *dto.SearchBlockContentParams, pa *paginate.Pager) ([]*models.BlockContent, *paginate.Pager, error)
	QueryByCode(code string) (*models.BlockContent, error)
	Query(id int64, code string) (*models.BlockContent, error)
	Save(id int64, b *models.BlockContent) (int64, error)
	GetFromCache(code string) (*models.BlockContent, error)
	Delete(id int64) (int64, error)
}

// ItfTelemetryService telemetry遥测service
type ItfTelemetryService interface {
	ItfMetricService
	ItfMetricDataService
}

// ItfMetricService metric service
type ItfMetricService interface {
	CheckCreateMetric(add *models.Metrics) (int64, error)     //检查创建metric
	CreateMetric(*models.Metrics) (int64, error)              //初始化一个测点的表
	QueryMetric(metricId int64) (*models.Metrics, error)      //查询某个测点信息
	QueryMetricByName(string string) (*models.Metrics, error) //查询某个测点信息
	NameByKeys(keys ...string) string                         //多个key生成key
}

// ItfMetricDataService metric数据service
type ItfMetricDataService interface {
	QueryLatestData(metricId int64) (*models.MetricData, error)                                                        //查询点位的最新数据
	SearchHistoryData(req *dto.SearchMetricDataDto, pa *paginate.Pager) ([]*models.MetricData, *paginate.Pager, error) //搜索历史测点数据
	QuerySumData(req *dto.SearchMetricDataDto) (*models.MetricValueData, error)                                        // 对指定历史数据条件的求和数据获取
	WriteData(...*models.MetricData) (int64, error)                                                                    //写入一个测点（覆盖）

	SearchStatData(req *dto.SearchMetricStatDto, pa *paginate.Pager) ([]*models.MetricStatValueData, *paginate.Pager, error) //搜索统计测点数据
	QueryStatData(req *dto.QueryMetricStatDto) (*models.MetricStatValueData, error)                                          //查询一个统计数据
	QueryStatSumData(req *dto.SearchMetricStatDto) (*models.MetricValueData, error)                                          // 对指定stat条件的求和数据获取
	WriteStat(data []*models.MetricStatData, merge bool) (int64, error)                                                      //写入一个统计数据（合并）
}

type ItfOrganizeService interface {
	Search(search dto.SearchOrganizeParams, pa *paginate.Pager) ([]*respdata.OrganizeListItem, *paginate.Pager, error)
	Tree(search dto.TreeOrganizeParams) ([]*dto.TreeNode[*models.Organize], error)

	Query(id int64) (*respdata.OrganizeDetail, error)
	Add(add models.Organize) (int64, error)
	Update(id int64, up models.Organize) (int64, error)
	Delete(id int64) (int64, error)
	Enable(id int64, status int) (int64, error) //
}

type ItfRegionDistrict interface {
	Query(code string) (dto.RegionItem, error)
	Districts(code string) ([]dto.RegionItem, error)
}
